﻿using System;
using System.Collections.Generic;
using NAnt.Core;
using NAnt.Core.Attributes;

namespace ECM7.NantContrib.Types
{
	public class IisBindingElement : Element
	{
		[TaskAttribute("port")]
		public int? Port { get; set; }

		[TaskAttribute("host")]
		public string Host { get; set; }

		[TaskAttribute("ip")]
		public string Ip { get; set; }

		[TaskAttribute("protocol")]
		public string Protocol { get; set; }

		public string GetBindingInfo()
		{
			return string.Format("{0}:{1}:{2}", Ip, Port ?? 80, Host);
		}

		public string GetProtocol()
		{
			return string.IsNullOrWhiteSpace(Protocol) ? "http" : Protocol.Trim();
		}
	}

	[Serializable]
	public class IisBindingElementCollection : List<IisBindingElement>
	{
		public IisBindingElementCollection()
		{
		}

		public IisBindingElementCollection(IisBindingElement value)
		{
			Add(value);
		}

		public IisBindingElementCollection(IEnumerable<IisBindingElement> value)
		{
			AddRange(value);
		}
	}
}
